package Package.FunctionalInterfaces.ConsumerInterface;

import java.util.function.Consumer;

public class ConsumerInterface {
    public static final void ConsumerInterface() {
//Consumer接口
//Consumer接口也被称为消费型接口，它消费的数据的数据类型由泛型指定
//        常用方法
//Consumer：包含两个方法
//方法名 说明
//void accept(T t) 对给定的参数执行此操作
//default Consumer andThen(Consumer
//after)
//返回一个组合的Consumer，依次执行此操作，然后执行
//after操作
        operatorString("ChangCun", (s) -> System.out.println(s));
        operatorString("ChangCun", S->System.out.println(new StringBuffer(S).reverse().toString()));
        System.out.println("------------------------------");
        operatorString("ChangCun",s->{
            System.out.println(s);
        },S->{
            System.out.println(new StringBuffer(S).reverse().toString());
        });
    }

    private static void operatorString(String name, Consumer<String> con) {
        con.accept(name);
    }

    private static void operatorString(String name, Consumer<String> con1, Consumer<String> con2) {
con1.andThen(con2).accept(name);
    }
}
